﻿using Microsoft.EntityFrameworkCore.Migrations;

namespace Infrastructure.Data.Data.Migrations.SQLite
{
    public partial class Initialize : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "GitLibaray",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
                    Account = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
                    Interval = table.Column<int>(type: "INTEGER", nullable: false),
                    Remember = table.Column<bool>(type: "INTEGER", nullable: false),
                    LocalDirectory = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false),
                    CreateDateTime = table.Column<long>(type: "INTEGER", nullable: false, defaultValueSql: "strftime('%s','now')"),
                    ModifyDateTime = table.Column<long>(type: "INTEGER", nullable: false, defaultValueSql: "strftime('%s','now')"),
                    Password = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
                    PasswordHash = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
                    GitUrl = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_GitLibaray", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SyncLog",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Message = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false),
                    GitLibarayId = table.Column<int>(type: "INTEGER", nullable: true),
                    CreateDateTime = table.Column<long>(type: "INTEGER", nullable: false, defaultValueSql: "strftime('%s','now')")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SyncLog", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SyncLog_GitLibaray_GitLibarayId",
                        column: x => x.GitLibarayId,
                        principalTable: "GitLibaray",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_GitLibaray_Account",
                table: "GitLibaray",
                column: "Account",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_SyncLog_GitLibarayId",
                table: "SyncLog",
                column: "GitLibarayId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SyncLog");

            migrationBuilder.DropTable(
                name: "GitLibaray");
        }
    }
}
